package com.ibm.cognos.imt.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

//import org.springframework.oxm.castor.CastorMarshaller;

@Configuration
//@EnableWebMvc
public class WebMvcConfig extends WebMvcConfigurerAdapter {

    @Bean
    public InternalResourceViewResolver internalResourceViewResolver() {
        InternalResourceViewResolver internalResourceViewResolver = new InternalResourceViewResolver();
        internalResourceViewResolver.setPrefix("/WEB-INF/view/");
        internalResourceViewResolver.setSuffix("jsp");
        return internalResourceViewResolver;
    }

//    @Bean
//    public VelocityConfigurer velocityConfigurer(){
//        VelocityConfigurer configurer = new VelocityConfigurer();
////        configurer.setResourceLoaderPath("/WEB-INF/html/");
//        return configurer;
//    }
//
//
//    @Bean
//    public VelocityViewResolver internalResourceViewResolver() {
//        VelocityViewResolver velocityViewResolver = new VelocityViewResolver();
//        velocityViewResolver.setPrefix("/WEB-INF/");
//        velocityViewResolver.setSuffix("html");
//        return velocityViewResolver;
//    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler("/assets/**").addResourceLocations("/assets/");
//        registry.addResourceHandler("/webjars/**").addResourceLocations("/webjars/");
        registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");

    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
    }

    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    @Bean
    public MultipartResolver multipartResolver() {
        return new org.springframework.web.multipart.commons.CommonsMultipartResolver();
    }

//    //limit size of upload file to 256K
//    @Bean
//    MultipartConfigElement multipartConfigElement() {
//        MultipartConfigFactory factory = new MultipartConfigFactory();
//        factory.setMaxFileSize("128KB");
//        factory.setMaxRequestSize("128KB");
//        return factory.createMultipartConfig();
//    }


//    @Bean
//    public ViewResolver viewResolver() {
//        ThymeleafViewResolver res = new ThymeleafViewResolver();
//
//        res.setOrder(1);
//        res.setContentType("text/html; charset=UTF-8");
//        res.setTemplateEngine(templateEngine());
//
//        return res;
//    }
//
//    private SpringTemplateEngine templateEngine() {
//        SpringTemplateEngine res = new SpringTemplateEngine();
//        res.setTemplateResolver(templateResolver());
////        res.addDialect(new LayoutDialect());
//        return res;
//    }
//
//
//    private TemplateResolver templateResolver() {
//        ServletContextTemplateResolver res = new ServletContextTemplateResolver();
//
//        res.setPrefix("/WEB-INF/");
//        res.setSuffix(".html");
//        res.setTemplateMode("HTML5");
//        res.setCharacterEncoding("UTF-8");
//
//        return res;
//    }

//    @Bean
//    public CastorMarshaller marshaller(){
//        return new CastorMarshaller();
//    }
}